/*
* The base class for other classes, like "Note" and "Block" etc.
* 
*/
function BaseClass(){
    /*Jim
    * Build the html string by Mustache. 
    * @param template | String | Required | the mustache template string, like ""<h1>{{firstName}} {{lastName}}</h1>Blog: {{blogURL}}"
    * @param json | Json | Required | the json used to build the html with mustache template
    * @return html | String | the html string result iss built by Mustache.js
    */
    this.buildHtml = function(template, json){
        return html = Mustache.to_html(template, json);
    }
    
    /*
    * Append the html string to $context. 
    * You can use BaseClass.buildHtml(template, json) to build the html string from Mustache template
    * and then append the built html string to $context(jQuery object).
    * @param htmlString | String | Required | html string, like "<p>xxx<p>"
    * @param $context | jQuery | Required | the jQuery object which will include the html string, like "$('body')"
	* @param clearChildren | Boolean | Optional | should clear all children element of the $context or not before the htmlString being appended
	*		 by defualt: true
	*		 true = { clear all children of the $context }, false = { just append to $context }
    */    
    this.appendHtml = function(htmlString, $context, clearChildren){
		if(clearChildren == undefined || clearChildren){
			$context.append(htmlString);
		}else{
			$context.children().remove();
			$context.append(htmlString);
		}		
    }

    /*
    * Check if number parameter is integer or not. 
    * i.e. 
    *       1, 2 or 3 etc. will return true, 
    *       and 2.1, 3.2(not integer) etc. will return false.
    * @param number | Any | Required | the parameter to be checked if it is integer
    * @return Boolean | true = { number parameter is integer }, false = { number parameter is not integer }
    */
    this.isInteger = function(number){
        // variables
        var isNumber = false;

        // make sure it is integer
        if(number.indexOf('.') == -1 && !isNaN(number)){
            isNumber = true;
        }

        return isNumber;
    }

    /*
    * Check if $object is an object or not.
    * @param $object | Any | Required | parameter to be checked if it is an object
    * @return Boolean | true = { $object is an object }, false = { $object is not an object }
    */
    this.isObject = function($object){
        // variables
        var isObject = false;

        // make sure $object parameter is object type
        if(typeof $object == 'object')
            isObject = true;

        return isObject;
    }

    /*
    * Check if $object is an valid object or not.
    * Valid object means $object.length should be > 0.
    * @param $object | Any | Required | parameter to be checked if it is an valid object
    * @return Boolean | true = { $object is a valid object }, false = { $object is not a valid object }
    */
    this.isValidObject = function($object){
        // variables
        var isValid = false;

        if(this.isObject($object) && $object.length > 0) isValid = true;

        return isValid;
    }

    this.hasChildren = function($object){
        // variables
        var hasChildren = false;

        if($object.children().length > 0){
            hasChildren = true;
        }else{
            hasChildren = false;
        }

        return hasChildren;
    }

    /*
    * Add block model to array.
    * @param blockArray | Array | Required | the array which includes all the block objects, this may come from Note object
    * @param  blockModel | BlockModel | the  block model, that is BlockModel object.
    * @return Boolean | true = { $object is a valid object }, false = { $object is not a valid object }
    */
    this.addBlocModelToArray = function(blockArray, blockModel, indexToAdd){
        // variables
        var isValid = false;

        if(this.isObject($object) && $object.length > 0) isValid = true;

        return isValid;
    }

    /*
    * Check if the index is valid one. This will check the following:
    *       1. index parameter is int.
    *       2. index should be in the scope.
    *          i.e. If a $context has 3 children nodes, then a new child is going to be inserted into the $context, the valid index should be [0-3].
    * @param blockArray | Array | Required | the array which includes all the block objects, this may come from Note object
    * @param  blockModel | BlockModel | the  block model, that is BlockModel object.
    * @return Boolean | true = { $object is a valid object }, false = { $object is not a valid object }
    */
    this.isValidIndex = function(index){
        // variables
        var isValid = false;

        this.isInteger()

        return isValid;
    }
}